<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quản lý nhóm quyền</title>
<link href="../Twitter_Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../CSS/css_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../CSS/validationEngine.jquery.css"/>

<script type="text/javascript" src="../Twitter_Bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="../Twitter_Bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="../Scripts/GroupRoleManagementJS.js"></script>
<style type="text/css">
<!--
#tbResult td,#tbResult th
{
	text-align:center;
}
-->
#tbResult tr.active:hover
{
	cursor:pointer;
}
</style>
</head>

<body>
<div class="container" id="Container">
<!--Menu top -->
  <div id="menu">
  	<?php
	include("MainMenu.php");
	include("../Connections/connect_admin.php");
	$page=1;
		$recordPerPage=10;
		if(isset($_GET["page"]))
			{
				$page=intval($_GET["page"]);
			}
		$index=($page-1)*$recordPerPage;
		$keyword='';
		 if(isset($_GET["keyword"]))
	  {
		$keyword=trim($_GET["keyword"]);
 		$query="SELECT * FROM grouprole g WHERE g.IsDeleted=0 AND (g.GroupName LIKE '%$keyword%' OR g.Description LIKE '%$keyword%') ORDER BY g.GroupName ";
		
	  }
	  else
	  {
		$query="SELECT * FROM grouprole g WHERE g.IsDeleted=0 ORDER BY g.GroupName ";
	  }
	  $sql=$query." Limit $index,$recordPerPage";
	  $result=mysql_query($sql);
	?>
	
    </div>
  </div>
   <div class="divTitle" style="margin-bottom:30px"><span class="titlePage" >Quản lý nhóm quyền</span></div>
  <div id="divContain">
  <!--GroupRole Info -->
  <div style="width:50%; float:left" >
  	<form action="" method="get" id="formSearch" class="form-horizontal">
 		<div class="input-append" style="width:350px">
        <input type="text" id="txtKeyword" name="keyword" placeholder="Từ khóa..." <?php if($keyword!='') echo "value='$keyword'"; ?>><button class="btn" type="submit" id="btnSearch"><i class=" icon-search"></i> Tìm kiếm</button>
       
        </div>
         <a type="button" class="btn btn-primary" id="btnAddGroupRole" href="#updateGroup" data-toggle="modal"><i class="icon-white icon-plus-sign"></i> Tạo nhóm</a>
    </form>
    
     <?php
	if(isset($_GET["e"]))
	{
		$error=intval($_GET["e"]);
		switch($error)
		{
			case 0:
	?>
    <div class="alert alert-success">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Thêm mới nhóm quyền THÀNH CÔNG</strong>
    </div>
    <?php
			break;
			case 1:
	?>
     <div class="alert alert-error">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Thêm mới nhóm quyền THẤT BẠI</strong>
    </div>
     <?php
	 		break;
			case 2:
	?>
     <div class="alert alert-success">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Cập nhật nhóm quyền THÀNH CÔNG</strong>
    </div>
     <?php
	 		break;
			case 3:
	?>
     <div class="alert alert-error">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Cập nhật nhóm quyền THẤT BẠI</strong>
    </div>
    <?php
			break;
		}	
		
	}
	?>
    
    <table class="table table-bordered table-striped  " id="tbResult" width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
  	<th scope="col" class="hide">Tên nhóm</th>
    <th scope="col">Tên nhóm</th>
    <th scope="col">Mô tả</th>
    <th scope="col">&nbsp;</th>
    <th scope="col">&nbsp;</th>
  </tr>
  <?php
 	while ($row=mysql_fetch_assoc($result))
	{
  ?>
  <tr class="active">
  	<td class="hide"><?php echo $row['GroupRoleID'];?></td>
    <td><?php echo $row['GroupName'];?></td>
    <td><?php echo $row['Description'];?></td>
    <td><a href="#" title="Xóa" class="delete"><img src="../Images/Icons/delete.png" alt="delete"/></a></td>
    <td><a href="#updateGroup" data-toggle="modal" title="Sửa" class="update"><img src="../Images/Icons/page_edit.png" alt="update" /></a></td>
   
  </tr>
  <?php }?>
</table>

<div class="pagination pull-right">
 		<?php require("process/funcPaging.php");
			
			if(isset($_GET["keyword"]))
			{
				$keyword=$_GET["keyword"];
				$link="GroupRole.php?keyword=".$keyword."&";
			}
			else
			{	
				$link="GroupRole.php?";
			}
			$resAll=mysql_query($query);
			$total=mysql_num_rows($resAll);
			
			Paging($total,$page,5,$recordPerPage,$link);
 		?>  
    </div>
  </div>
  <!--GroupRole Detail -->
  <div style="width:45%; float:right">
  <div class="divTitle" style="margin-bottom:30px"><span class="titlePage" id="GroupName" >Chi tiết nhóm</span></div>
  <input type="hidden" id="grouproleID" />
  	<ul class="nav nav-tabs">
    <li class="active"><a href="#user" data-toggle="tab">Người dùng</a></li>
    <li><a href="#role" data-toggle="tab">Quyền</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="user">
        <a  id="btnAddUser" class="btn btn-primary hide" href="#updateUsers" data-toggle="modal" ><i class="icon-white icon-user"></i> Thêm người</a><br />
        <div style=" max-height:400px; overflow:auto; padding-top:3px">
        	<table class="table table-strip" width="100%" border="0" cellspacing="0" cellpadding="0" id="tbUsers" >
                 <!-- <tr>
                    <td>Người dùng 1</td>
                    <td >Họ tên</td>
                    <td><a href="#" class="delete" title="Xóa"><img src="../Images/Icons/delete.png" /></a></td>
                  </tr> -->
                  
                </table>
			</div>
        </div>
        <div class="tab-pane" id="role">
        	 <a id="btnAddRole" class="btn btn-primary hide" href="#updateRoles" data-toggle="modal" ><i class="icon-white icon-ok" ></i> Thêm Quyền</a><br />
        <div style=" max-height:400px; overflow:auto; padding-top:3px">
        	<table class="table table-strip" width="100%" border="0" cellspacing="0" cellpadding="0" id="tbRoles" >
                 <!-- <tr>
                  	<td class="hide"></td>
                    <td width="70%">Quyền 1</td>
                    <td><a href="#" class="delete" title="Xóa"><img src="../Images/Icons/delete.png" /></a></td>
                  </tr> -->
                  
                </table>
			</div>
        </div>
    </div>
  </div>
  <!--footer -->
  </div>
  <div id="footer">
      <?php
	  include("Footer.php");
	  ?>
  </div>
</div>

<!---------------------------Popup Thêm/Cập nhật nhóm người dùng----------------------------->
    <div class="modal hide fade"  id="updateGroup">
    <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3></h3>
    </div>
    <form action="process/GroupRole_process.php" method="post" id="formGroupRole" style="margin-bottom:0px">
    <div class="modal-body">
    <p>
    	<input type="hidden" id="task" name="task" />
		<input type="hidden" id="groupid" name="groupid" />

        	<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td>Tên nhóm</td>
                    <td><input name="groupname" type="text" id="txtGroupRoleName" class="validate[required]" /></td>
                  </tr>
                    <td>Mô tả:</td>
                    <td><textarea id="txtDescription" rows="3" name="desc"></textarea></td>
                  </tr>
                  
              </table>

       
    </p>
    </div>
    <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Đóng lại</a>
    <button type="submit" class="btn btn-primary" id="btnSave">Cập nhật</button>
    </div>
     </form>
    </div>
    
    <!---------------------------Popup Thêm người dùng của nhóm quyền----------------------------->
    <div class="modal hide fade"  id="updateUsers">
    <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>Thêm người dùng vào nhóm</h3>
    </div>
    <form action="" method="post" id="formUsers" style="margin-bottom:0px">
    <div class="modal-body">
    
    	
		<div class="input-append form-horizontal">
        <input type="text" id="txtUserKey"  placeholder="Từ khóa..." ><button class="btn" type="button"  id="btnSearchUser"><i class="icon-search"></i> Tìm kiếm</button>
        </div>
        <p style="max-height:400px">
     <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-bordered table-striped" id="tbSelectUsers">
                     	<tr>
                                <th width="20px"><input type="checkbox" id="selectAllUsers" /></th>
                                <th>Tên đăng nhập</th>
                                <th>Họ tên</th>
                         </tr>
                         <!--<tr>
                                <td width="20px"><input type="checkbox"/></td>
                                <td>Mã quyền</td>
                                <td>Tên quyền</td>
                         </tr> -->
                             
                    </table>

       </p>
    
    </div>
    <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Đóng lại</a>
    <input type="button" value="Cập nhật" class="btn btn-primary" id="addUsers" />
    </div>
     </form>
    </div>
     <!---------------------------Popup Thêm quyền của nhóm quyền----------------------------->
    <div class="modal hide fade"  id="updateRoles">
    <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>Thêm quyền cho nhóm</h3>
    </div>
    <form action="" method="post" id="formRoles" style="margin-bottom:0px">
    <div class="modal-body">
    
    	<div class="input-append form-horizontal">
        <input type="text" id="txtRoleKey"  placeholder="Từ khóa..." ><button class="btn" type="button"  id="btnSearchRole"><i class="icon-search"></i> Tìm kiếm</button>
        </div>
       <p style="max-height:400px">
 					<table width="100%" cellspacing="0" cellpadding="0" class="table table-bordered table-striped" id="tbSelectRoles">
                     	<tr>
                                <th width="20px"><input type="checkbox" id="selectAllRoles" /></th>
                                <th>Mã quyền</th>
                                <th>Tên quyền</th>
                         </tr>
                         <tr>
                                <td width="20px"><input type="checkbox"/></td>
                                <td>Mã quyền</td>
                                <td>Tên quyền</td>
                         </tr>
                             
                    </table>
       </p>
    
    </div>
    <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Đóng lại</a>
    <input type="button" value="Cập nhật" class="btn btn-primary" id="addRoles" />

    </div>
     </form>
    </div>
 <script>
		//-----------------------Validation----------------------------------
			$(document).ready(function(){
							   $("#formGroupRole").validationEngine();
							   });
	</script>
</body>
</html>
